package cn.gok.oa.attendance.controller;


import cn.gok.oa.attendance.entity.TbApply;
import cn.gok.oa.attendance.service.ITbApplyService;
import cn.gok.oa.log.LogAnnotation;
import cn.gok.oa.util.ResultData;
import com.auth0.jwt.JWT;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author gok
 * @since 2022-08-04
 */
@RestController
@RequestMapping("/apply")
public class TbApplyController {
    @Autowired
    ITbApplyService iTbApplyService;

    @RequestMapping(value = "/apply",method = RequestMethod.POST)
    @LogAnnotation("插入补打卡数据")
    public ResultData insert(int attendanceId){
        int temp = iTbApplyService.apply(attendanceId);
        if (temp > 0){
            return ResultData.success();
        }else {
            return ResultData.fail();
        }

    }
    @RequestMapping(value = "/query",method = RequestMethod.GET)
    @LogAnnotation("获取补签列表")
    public ResultData query(HttpServletRequest httpServletRequest){
        String token = httpServletRequest.getHeader("token");
        int userId = (Integer.parseInt(JWT.decode(token).getAudience().get(0)));
        List<TbApply> applyList = iTbApplyService.queryByUserId(userId);
        ResultData result = new ResultData();
        result.setData(applyList);
        result.setCode("0");
        result.setMsg("操作成功");
        return result;
    }

}
